package com.hirsi.module.manager.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hirsi.core.vo.param.PageParam;
import com.hirsi.core.vo.result.PageResult;
import com.hirsi.module.manager.entity.Manager;
import com.hirsi.module.manager.mapper.ManagerMapper;
import com.hirsi.module.manager.service.ManagerService;
import com.hirsi.module.manager.vo.EditManagerVo;
import com.hirsi.module.manager.vo.param.ChangeManagerStatusParam;
import com.hirsi.module.manager.vo.param.QueryManagerParam;
import com.hirsi.module.manager.vo.result.ManagerResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "管理人员相关接口")
@ApiSupport(order = 2)
@RestController
@RequestMapping("v1/manager")
public class ManagerController {

    @Autowired
    private ManagerMapper managerMapper;

    @Autowired
    private ManagerService managerService;

    @ApiOperation("分页查询管理员列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("page")
    public PageResult<ManagerResult> page(PageParam page, QueryManagerParam param) {
        return PageResult.parse(managerMapper.page(page.pager(), param));
    }

    @ApiOperation("编辑回显管理员信息")
    @ApiOperationSupport(order = 2)
    @GetMapping("edit")
    public EditManagerVo edit(@ApiParam(value = "管理员id", required = true) @RequestParam Integer id) {
        return managerService.edit(id);
    }

    @ApiOperation("保存管理员信息")
    @ApiOperationSupport(order = 3)
    @PostMapping("save")
    public void save(@RequestBody EditManagerVo vo) {
        managerService.save(vo);
    }

    @ApiOperation("删除管理员")
    @ApiOperationSupport(order = 4)
    @PostMapping("delete")
    public void delete(@RequestBody List<Integer> ids) {
        managerService.delete(ids);
    }

    @ApiOperation("修改管理员状态")
    @ApiOperationSupport(order = 5)
    @PostMapping("change_status")
    public void changeStatus(@RequestBody ChangeManagerStatusParam param) {
        managerService.lambdaUpdate()
                .eq(Manager::getId, param.getId())
                .set(Manager::getStatus, param.getStatus()).update();
    }

    @ApiOperation("根据部门id分页查询管理员列表")
    @ApiOperationSupport(order = 6)
    @GetMapping("page_by_department")
    public PageResult<ManagerResult> pageByDepartment(PageParam page, @ApiParam(value = "部门id", required = true) @RequestParam Integer departmentId) {
        return PageResult.parse(managerMapper.pageByDepartmentId(page.pager(), departmentId));
    }
}
